package IOperation;

import book.Book;
import book.Booklist;

import java.util.Scanner;

/*
 *Description:
 *User:laoHu
 *Created with Intellij IDEA 2025
 *Data:2025.05.00
 *Time:00:00
 */
public class RetBook implements ioperation{
    @Override
    public void work(Booklist booklist) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要归还的书籍名称:>");
        String bookname = scanner.nextLine();

        //判断
        int currentNum = booklist.getBookCount();
        int i = 0;
        for (; i < currentNum; i++) {
            Book book = booklist.getBooks(i);
            //判断
            if(book.getBookname().equals(bookname)){
                break;//找到了
            }
        }

        //找不到
        if(i == currentNum) System.out.println("输人的书籍名称不存在！！！");
        //找到了
        //1.归还,设置未借出
        Book book = booklist.getBooks(i);
        book.isBorrowed = false;
        //2.提示一下
        System.out.println(book.getBookname() +"归还成功");
    }
}
